﻿using ASPApiDemo.Model;
using AutoMapper;

namespace ASPApiDemo
{
    public class CustomProfile : Profile
    {
        //在构造函数中定义映射关系
        //实体模型和视图模型之间的相互转换
        public CustomProfile()
        {
            // 当然这里是因为字段不一样，所以需要手动指定
            // 如果字段一样的话，AutoMapper会自动映射
            CreateMap<User, UserVo>()
                .ForMember(dest => dest.UserName, opt => opt.MapFrom(src => src.Name));
            CreateMap<UserVo, User>()
                .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.UserName));
            CreateMap<Role, RoleVo>()
                 .ForMember(dest => dest.RoleName, opt => opt.MapFrom(src => src.Name));
            CreateMap<RoleVo, Role>()
                .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.RoleName));
        }
    }
}
